<template>
	<view>
		<view class="custom-form">
			<uv-form label-position="top" label-width="150">
				<uv-form-item label="转入金额">
					<uv-input placeholder="请输入" v-model="amount" type="number" :clearable="false">
						<template v-slot:suffix>
							<uv-button type="primary" text="全部" size="mini" @click="allAmount"></uv-button>
						</template>
					</uv-input>
				</uv-form-item>
				<uv-form-item label="支付密码">
					<uv-input placeholder="请输入" v-model="payPwd" :clearable="false" :password="true"></uv-input>
				</uv-form-item>
				<uv-form-item label="支付方式">
					<view class="pay-ways">
						<view class="pay-way" @click="changeBalanceType('1')">
							<view class="pay-way-icon">
								<uv-icon name="checkmark-circle-fill"
									:color="balanceType == '1' ? '#2979ff' : '#cecece'" size="24"></uv-icon>
							</view>
							<view class="pay-way-right">
								<view class="pay-way-title">账户余额</view>
								<view class="pay-way-value">可用<text>{{memberInfo.accountBalance}}</text>USDT</view>
							</view>
						</view>
						<uv-gap height="1" bgColor="#e2e2e2"></uv-gap>
						<view class="pay-way" @click="changeBalanceType('2')">
							<view class="pay-way-icon">
								<uv-icon name="checkmark-circle-fill"
									:color="balanceType == '2' ? '#2979ff' : '#cecece'" size="24"></uv-icon>
							</view>
							<view class="pay-way-right">
								<view class="pay-way-title">投资余额</view>
								<view class="pay-way-value">可用<text>{{memberInfo.investBalance}}</text>USDT</view>
							</view>
						</view>
					</view>
				</uv-form-item>
			</uv-form>
		</view>
		<view class="fixed-bottom">
			<view class="fixed-bottom-inner">
				<uv-button type="primary" text="立即转入" size="large" @click="buyIn"></uv-button>
			</view>
		</view>

	</view>
</template>

<script>
	import common from '@/common/common'
	export default {
		data() {
			return {
				amount: '',
				payPwd: '',
				memberInfo: '',
				balanceType: '1',
			}
		},
		onLoad(option) {
			this.getMemberInfo();
		},
		methods: {

			changeBalanceType(balanceType) {
				this.balanceType = balanceType;
			},

			allAmount() {
				this.amount = this.balanceType == '1' ? this.memberInfo.accountBalance : this.memberInfo.investBalance;
			},

			buyIn() {
				var that = this;
				if (that.amount == null || that.amount == '') {
					uni.showToast({
						title: "请输入转入金额",
						icon: "none"
					});
					return;
				}
				if (that.payPwd == null || that.payPwd == '') {
					uni.showToast({
						title: "请输入支付密码",
						icon: "none"
					});
					return;
				}
				uni.$uv.http.post('/balanceFinancing/buyIn', {
					buyInAmount: that.amount,
					balanceType: that.balanceType,
					payPwd: that.payPwd,
				}).then(res => {
					uni.showToast({
						icon: 'success',
						title: '操作成功',
						duration: 2000,
						complete: function() {
							uni.navigateBack({
								success: function() {
									uni.$emit('balanceFinancingBuyInRefresh', '1');
								}
							});
						}
					});
				});
			},

			getMemberInfo() {
				var that = this;
				uni.$uv.http.get('/member/getMemberInfo').then(res => {
					that.memberInfo = res.data;
				});
			},

			moneyFormat(amount) {
				return common.moneyFormat(amount);
			},
		}
	}
</script>

<style>
	.custom-form {
		padding-left: 32rpx;
		padding-right: 32rpx;
	}

	.pay-ways {
		width: 100%;
	}

	.pay-ways-title {
		border-bottom: 2rpx solid rgb(233, 235, 239);
		color: #000;
		font-weight: 400;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		line-height: 2;
	}

	.pay-way {
		display: flex;
		align-items: center;
		padding-bottom: 16rpx;
		padding-top: 16rpx;
	}

	.pay-way-right {
		flex: 1;
	}

	.pay-way-icon {
		padding-right: 16rpx;
	}

	.pay-way-title {
		color: #000;
		line-height: 52rpx;
		font-size: 30rpx;
	}

	.pay-way-value {
		color: rgba(0, 0, 0, .4);
		font-size: 26rpx;
	}

	.pay-way-value text {
		color: #000;
		padding-left: 6rpx;
	}
</style>